function [ x ] = faft( x,filterLen )
    N = length(x);  
    lambda = 0;
    w =  dbaux(filterLen);
    [lpd,hpd] = orthfilt(w); 
    [ A B C D ] = creatingCircRecon( N,filterLen );
    
    clear vecLp vecHp
    [c ,r] = size(x);
    tic
    for k = 1:r;
        x(:,k) = sparse(recFaft(full(x(:,k)),filterLen,A,B,C,D,lpd,hpd,lambda,1));
    end
    toc
   % x = x';
 %   for k = 1:r
  %       x(k,:) = recFaft(full(x(k,:)),A,B,C,D,lpd,hpd,lambda,1);
%    end
%    x = x';
end

function [x] = recFaft(x,filterLen,A,B,C,D,lpd,hpd,lambda,s)
    n2 = length(x)/2;
    if(n2 <= filterLen)
        x = fft(x);
    else
        [c,d] = dwt(x,lpd,hpd,'mode','per');
        c(abs(c)<lambda) = 0;
        d(abs(d)<lambda) = 0;
        if(~isempty(find(c,1)))
           c = recFaft(c,filterLen,A,B,C,D,lpd,hpd,lambda,s*2);
        end
        if(~isempty(find(d,1)))
           d = recFaft(d,filterLen,A,B,C,D,lpd,hpd,lambda,s*2);
        end
        c(abs(c)<lambda) = 0;
        d(abs(d)<lambda) = 0;
        x = [(A(1:s:end).*c + B(1:s:end).*d); (C(1:s:end).*c+D(1:s:end).*d)]; 
       
    end
end


%this function returns the waveletcoefficents 
function [c,d] = fwt(x,lpd,hpd)
    n = length(x);
    n2 = n / 2;
    l = sparse(1:filterLen,ones(1,filter), lpd,n,1);
    h = sparse(1:filterLen,ones(1,filter), hpd,n,1);
    c = sparse(n2,1);
    d = sparse(n2,1);
    for k = 1:n2
        c(k) = x.'* circshift(l,k*2);
        d(k) = x.'* circshift(h,k*2);
    end
end